package com.example.server.service.impl;

import com.example.server.mapper.Mapper1;
import com.example.server.pojo.CityLevel;
import com.example.server.pojo.Line;
import com.example.server.pojo.Income;
import com.example.server.pojo.Education;
import com.example.server.service.Service1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;


@Service
public class Impl implements Service1 {
    @Autowired
    private Mapper1 mapper;
    public Line getEducation() {
        List<String> educationList = Arrays.asList("无学历","小学","初中","高中","大学");
        return func(educationList,"education");
    }
    public Line getIncome() {
        List<String> incomeList = Arrays.asList("0~2k", "2k~4k", "4k~6k", "6k~8k", "8k~10k", "10k+");
        return func(incomeList,"income");
    }

//    @Override
//    public List<Education> getEducationZhanbiIn25W() {
//        return mapper.getEducationZhanbiIn25("female");
//    }
//    public List<Education> getEducationZhanbiIn25M() {
//        return mapper.getEducationZhanbiIn25("male");
//    }
    public List<Education> getEducationZhanbiIn25() {
        return mapper.getEducationRatioIn25();
    }
    public List<CityLevel> getCityLevelRatioIn25() {
        return mapper.getCityLevelRatioIn25();
    }
    public List<Income> getIncomeRatioIn25() {
        return mapper.getIncomeRatioIn25();
    }
    public Line getCityLevel(){
        List<String> cityLevelList = Arrays.asList("一线城市", "二线城市", "三线城市");
        return func(cityLevelList,"city_level");
    }
    public Line getSex(){
        List<String> sexList = Arrays.asList("female", "male");
        return func(sexList,"sex");
    }
    public Line func(List<String> list, String name){
        Line line = new Line();
        List<String> ageList = mapper.getAgeList();
        line.setAge(ageList);
        for (String edu : list) {
            List<Double> rate = mapper.getByEducation(name,edu);
            line.getRate().add(rate);
        }
        return line;
    }
}
